package com.elgenring.basic.service.impl;

import com.elgenring.basic.mapper.BaseMapper;
import com.elgenring.basic.query.BaseQuery;
import com.elgenring.basic.service.IBaseService;
import com.elgenring.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T>{

    @Autowired
    private BaseMapper<T> baseMapper;

    /**
     * @Title: loadAll
     * @Description: 查询所有
     * @Author: Atlas
     * @Version: 1.0
     * @Date:  2022/6/21 21:25
     * @Parameters:
     * @Return
     */
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    /**
     * @Title: loadById
     * @Description: 查询单个
     * @Author: Atlas
     * @Version: 1.0
     * @Date:  2022/6/21 21:25
     * @Parameters:
     * @Return
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /**
     * @Title: save
     * @Description: 新增
     * @Author: Atlas
     * @Version: 1.0
     * @Date:  2022/6/21 21:26
     * @Parameters:
     * @Return
     */
    @Override
    public void save(T t) {

        baseMapper.save(t);
    }

    /**
     * @Title: remove
     * @Description: 删除
     * @Author: Atlas
     * @Version: 1.0
     * @Date:  2022/6/21 21:31
     * @Parameters:
     * @Return
     */
    @Override
    public void remove(Long id) {

        baseMapper.remove(id);
    }

    /**
     * @Title: update
     * @Description: 修改
     * @Author: Atlas
     * @Version: 1.0
     * @Date:  2022/6/21 21:32
     * @Parameters:
     * @Return
     */
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    /**
     * @Title: 封装内容数量与内容数据
     * @Description: TODO
     * @Author: Atlas
     * @Version: 1.0
     * @Date:  2022/6/21 21:26
     * @Parameters:
     * @Return
     */
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {

        List<T> rows = baseMapper.queryData(baseQuery);

        Integer total = baseMapper.queryCount(baseQuery);

        return new PageList(total, rows);
    }

    @Override
    public void batRemove(Long[] ids) {
        baseMapper.batRemove(ids);
    }
}
